<!DOCTYPE html>
<html lang="en">
{include file="Public/head"}

<style>
    ul.group-list li {
        white-space: nowrap;float: left;
        width: 150px; height: 25px;
        padding: 3px 5px;list-style-type: none;
        list-style-position: outside;border: 0px;margin: 0px;
    }
    input[type=checkbox], input[type=radio] {
        display: inline-block;
    }
    .am-u-sm-2{
        float: left;
    }
    .diz_window li{
        border: #3bb4f2 solid 1px;
    }
    .diz_window .am-btn-danger{
    }

</style>


<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper" >
        <div class="row-content am-cf">
            <div class="row">

                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">新增</div>
                            <div class="widget-function am-fr">
                                <a href="javascript:;" class="am-icon-cog"></a>
                            </div>
                        </div>
                        <div class="widget-body am-fr">

                            <form id="roleform" form="submit" class="am-form tpl-form-border-form tpl-form-border-br">
                                {include file='Public:site'}
                                <div class="am-form-group">
                                    <label for="user-phone" class="am-u-sm-3 am-form-label">发票抬头</label>
                                    <div class="am-u-sm-2" style="float: left;">
                                        <input type="text" class="tpl-form-input" name="invoice_title" placeholder="发票抬头">
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <div class="am-u-sm-9 am-u-sm-push-3">
                                        <a onclick="javascript:history.back(-1);" ><input class="btn btn-default" type="reset" value="返回"></a>
                                        <input class="btn btn-info" type="submit"  value="提交">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}
{include file='Public:validation'}


<script>
    //搜索search
    function search(){

        var param = new Object();
        param['name']   = $("[name='name01']").val();
        $.post("{:url('search')}", param, function (res) {
            res = res + '<option value="0">匿名用户</option>';
            $('[name="user_id"]').html(res);
        });


    }
    {include file='Public:site_script'}
    //添加商品页
    function add_comm() {
        layer.open({type: 1, title: "添加商品", area: ['50%', '70%'], shade: 0.5});
        var openHtml = '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">\n' +
            '                                    <thead>\n' +
            '                                    <tr>\n' +
            '                                        <th>商品名称</th>\n' +
            '                                        <th>商品规格</th>\n' +
            '                                        <th>价格</th>\n' +
            '                                        <th>库存</th>\n' +
            '                                        <th>操作</th>\n' +
            '                                    </tr>\n' +
            '                                    </thead>\n' +
            '                                    <tbody>\n' +
            '                                    {foreach name="comm" key="key" item="value"}\n' +
            '                                    {notempty name="$value.spec"}' +
            '                                    {foreach name="$value.spec" key="k" item="v"}' +
            '                                    <tr class="gradeX">\n' +
            '                                        <td>{$value.goods_name}</td>\n' +
            '                                        <td>{$v.key_name}{$v.key}</td>\n' +
            '                                        <td>{$v.price}</td>\n' +
            '                                        <td>{$v.store_count}</td>\n' +
            '                                        <td>\n' +
            '                                            <div class="tpl-table-black-operation">\n' +
            // '                                                <a  onclick="comm_add({$value.goods_id},{$value.goods_name},{$value.market_price})">\n' +
            '                                                <a  onclick="comm_add({$value.goods_id},\'{$value.goods_name}\',{$v.price},\'{$v.key_name}\',\'{$v.key}\')">\n' +
            '                                                     确认\n' +
            '                                                </a>\n' +
            '                                            </div>\n' +
            '                                        </td>\n' +
            '                                    </tr>\n' +
            '                                    {/foreach}' +
            '                                     {else }' +
            '                                    <tr class="gradeX">\n' +
            '                                        <td>{$value.goods_name}</td>\n' +
            '                                        <td></td>\n' +
            '                                        <td>{$value.shop_price}</td>\n' +
            '                                        <td>{$value.store_count}</td>\n' +
            '                                        <td>\n' +
            '                                            <div class="tpl-table-black-operation">\n' +
            // '                                                <a  onclick="comm_add({$value.goods_id},{$value.goods_name},{$value.market_price})">\n' +
            '                                                <a  onclick="comm_add({$value.goods_id},\'{$value.goods_name}\',{$value.shop_price},\'无\')">\n' +
            '                                                     确认\n' +
            '                                                </a>\n' +
            '                                            </div>\n' +
            '                                        </td>\n' +
            '                                    </tr>\n' +
            '                                      {/notempty}' +
            '                                    {/foreach}\n' +
            '                                    <!-- more data -->\n' +
            '                                    </tbody>\n' +
            '                                </table>';
        $(".layui-layer-content").html(openHtml);
    }
    //确认商品
    //$goods_id 商品id
    function comm_add($goods_id,$goods_name,$market_price,$key_name,$key) {
        layer.closeAll('page');
        var flag=true;
        $i=0;
        if ($("#gradeX").html()!=""){
            $(".gradeX").each(function(){ //遍历所有商品
                $goods_ids=  $(this).children(".goods_id").val();  //商品id
                $spec=  $(this).children(".keys").val();  //商品规格
                $i++;
                if ($goods_ids==$goods_id&&$spec==$key) {
                    layer.msg('该商品已有', {shade: 0.5, time: 1000,icon: 2});
                     flag=false;
                    return false;

                }
            });
        }
        if (!flag){
            return false;
        }

        var res2=
            '                                    <tr class="gradeX">\n' +
            '                                        <input type="hidden" class="goods_id" name="goods['+$i+'][goods_id]" value="'+$goods_id+'"> \n' +
            '                                        <td>'+$goods_name+'</td>\n' +
            '                                        <td>'+$key_name+'</td>\n' +
            '                                        <input type="hidden"  class="keys"  name="goods['+$i+'][key]" value='+$key+'> \n' +
            '                                        <td>'+$market_price+'</td>\n' +
            '                                        <td><input type="text" name="goods['+$i+'][num]" value="1"></td>\n' +
            '                                        <td> <a onclick="javascript:$(this).parent().parent().remove()" href="javascript:void(0);" href="javascript:;" class="tpl-table-black-operation-del">\n' +
            '                                                    删除\n' +
            '                                                </a></td>\n' +
            '                                    </tr>\n' ;
            // '                                    <!-- more data -->\n' + $('#gradeX').html();

            $('#gradeX').append(res2);

    }

    //提交
    function roleSubmit(){
        var form=document.getElementById("roleform");
        var formData=new FormData(form);
        $.ajax({
            url:"{:Url('addData')}",
            type:'POST',
            data:formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success:function(res){
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 2000,icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function(){
                    // window.location.href=document.referrer;

                });
            }
        });
    }
</script>

</html>